package reflect;

import java.util.Scanner;

/**
 * 输入任意一个类，如果该类被注解@AutoRunClass标注了，
 * 则实例化对象
 * 没有标注，则提示
 */
public class Test2 {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入类名：");
        String s = scan.next();
        Class cls = Class.forName(s);
        boolean mark = cls.isAnnotationPresent(AutoRunClass.class);
        if (mark){
            System.out.println("实例化:"+cls.getName());
            Object obj = cls.newInstance();
            System.out.println(obj);
        }else {
            System.out.println("没有被标记！");
        }
    }
}
